﻿using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Isuka.Automation;

namespace Isuka.Excel.Events
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [TypeLibType(TypeLibTypeFlags.FHidden)]
    public sealed class DocEvents
        : EventSink<IDocEvents>
        , IDocEvents
    {
        XWorksheet worksheet;

        public DocEvents(XWorksheet worksheet)
            : base(worksheet)
        {
            Contract.Requires(worksheet != null);
            this.worksheet = worksheet;
        }

        public event Action<XRange> ChangeEvent;

        #region IDocEvents メンバー

        public void SelectionChange(object target)
        {
        }

        public void BeforeDoubleClick(object target, ref bool cancel)
        {
        }

        public void BeforeRightClick(object target, ref bool cancel)
        {
        }

        public void Activate()
        {
        }

        public void Deactivate()
        {
        }

        public void Calculate()
        {
        }

        public void Change(object target)
        {
            if (worksheet != null && target != null && ChangeEvent != null)
            {
                var x = new XRange(worksheet, target);
                var handler = ChangeEvent;
                if (handler != null)
                {
                    handler(x);
                }
            }
        }

        public void FollowHyperlink(object target)
        {
        }

        public void PivotTableUpdate(object target)
        {
        }

        #endregion

    }
}
